﻿using Fall.Core.BaseModels;
using System;
using System.Linq;
using System.Linq.Expressions;

namespace Fall.EntityFrameworkCore.Extensions
{
    public static class LinqExtensions
    {
        public static IQueryable<TSource> WhereIf<TSource>(this IQueryable<TSource> source, bool condition, Expression<Func<TSource, bool>> predicate)
        {
            if (condition)
            {
                return source.Where(predicate);
            }
            return source;
        }
        public static IQueryable<TSource> PageBy<TSource, TEntity>(this IQueryable<TSource> source, TEntity entity)
            where TEntity : PagedInput
        {
            return source.Skip(entity.SkipCount).Take(entity.MaxCount);
        }
    }
}
